<template>
	<div>
		<img style="width: 100%;" :src="info.image" mode='widthFix' alt="">
		<u-popup :show="show" mode="center" round='10px' :customStyle="{width:'100vw'}" :safeAreaInsetBottom='false'
			@close='popupClose' bgColor='transparent'>
			<view style="margin-top: 20px;">
				<div v-if='registerType == "1"' style="padding: 20rpx;position: relative;">
					<img style="width: 100%;" :src="baseUrl+'/static/operation/tc-error02.png'" mode='widthFix' alt="">
					<img @click='btnClick'
						style="position: absolute;bottom: 15vw;left: 0 ;width: 50%;left: 50%;transform: translateX(-50%);"
						mode='widthFix' :src="baseUrl+'/static/operation/tc-error-button.png'" alt="">
				</div>
				<div v-else style="padding: 20rpx;">
					<img style="width: 100%;" :src="baseUrl+'/static/operation/tc-success02.png'" mode='widthFix'
						alt="">
				</div>
				<div style="margin-top: -20px;display: flex;justify-content: center;">
					<u-icon @click="show = false" name="close-circle" size="36px" color="#fff"></u-icon>
				</div>
				<div style="margin-top: 0px;">
					<img style="width: 100%;" :src="baseUrl+'/static/operation/tc-success03.png'" mode='widthFix'
						alt="">
				</div>
			</view>
		</u-popup>
	</div>
</template>

<script>
	import {
		homeIndex
	} from "@/api/axios/operation.js";
	var QQMapWX = require("../../api/qqmap-wx-jssdk.min.js");
	var qqmapsdk = new QQMapWX({
		key: "LLDBZ-YFGW4-57ZUW-FFH4P-XPUL5-A4BQT",
	});
	import store from "@/store/index.js";
	export default {
		data() {
			return {
				staticURL: this.staticURL,
				index: 0,
				info: {},
				show: true,
				baseUrl: this.staticURL,
				registerType: '',
				customerType: '',
				mapData: {},
				localCoordinate: '',
				locationObj: '',
				deviceInfo: ''
			}
		},
		methods: {
			popupClose() {
				this.show = false;
			},
			btnClick() {
				if (this.customerType == '0') {
					uni.redirectTo({
						url: '/pages-operation/home/index'
					})
				}

			}
		},
		onHide: function() {
			this.saveActivityClue({
				activityImageId: this.info.id,
				startDate: this.startDate,
				location: this.locationObj,
				longitudeAndLatitude: this.localCoordinate,
				endDate: this.currentTime(),
				deviceInfo: this.deviceInfo
			})
			console.log({
				activityImageId: this.info.id,
				startDate: this.startDate,
				location: this.locationObj,
				longitudeAndLatitude: this.localCoordinate,
				endDate: this.currentTime(),
				deviceInfo: this.deviceInfo
			});
		},
		onShow: function() {
			console.log("home  Hide");
			this.startDate = this.currentTime()
			// if (this.info.id) {
			// 	this.saveActivityClue({
			// 		activityImageId: this.info.id,
			// 	})
			// }

		},
		onLoad() {
			homeIndex({}).then((res) => {
				console.log(res);
				this.info = res;
				this.saveActivityClue({
					activityImageId: this.info.id,
					startDate: this.startDate,
					location: this.locationObj ? this.locationObj : null,
					longitudeAndLatitude: this.localCoordinate ? this.localCoordinate : null,
					endDate: null,
					deviceInfo: this.deviceInfo
				})
			});

			// 手机信息
			let _this = this
			wx.getSystemInfo({
				success: function(res) {
					console.log("wx.getSystemInfo")
					console.log(res)
					_this.deviceInfo = res.brand
				}
			});
			// 获取地理信息
			uni.getLocation({
				type: "gcj02",
				success: function(res) {
					qqmapsdk.reverseGeocoder({
						location: {
							latitude: res.latitude,
							longitude: res.longitude,
						},
						complete(mapData) {
							mapData.result.location = {
								lat: res.latitude,
								lng: res.longitude,
							};

							_this.mapData = mapData.result;
							store.state.mapData = mapData.result;
							_this.localCoordinate = mapData.result.location.lat + ',' + mapData.result
								.location.lng
							_this.locationObj = {
								city: mapData.result.address_component.city,
								district: mapData.result.address_component.district,
								province: mapData.result.address_component.province,
								address: mapData.result.formatted_addresses.standard_address,
							}
							uni.setStorageSync("mapData", this.localCoordinate);
							uni.setStorageSync("locationObj", _this.locationObj);
							console.log('mapData', mapData);
						},
					});
				},
			});


			this.registerType = uni.getStorageSync('registerType')
			this.customerType = uni.getStorageSync('customerType')




		}
	}
</script>

<style>
</style>